package com.framework.service.yhbservice.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.YHBDao.transactionDao.YhbTransactionDao;
import com.framework.entity.tran.TranTransactionInfo;
import com.framework.page.PageUtils;
import com.framework.service.yhbservice.YhbTransactionService;
import com.framework.service.yhbservice.YhbUserService;
import com.framework.utils.PackUtils;
import com.framework.yhbEntity.user.YhbUser;
import com.framework.yhbEntity.view.CusTranView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("yhbTransactionService")
public class YhbTransactionServiceImpl extends ServiceImpl<YhbTransactionDao,TranTransactionInfo> implements YhbTransactionService {

    @Autowired
    private YhbUserService yhbUserService;

    @Override
    public List<Map<String, Object>> queryTransactionList(String token, String sn) {
        YhbUser user = yhbUserService.queryUserByToken(token);
        List<Map<String, Object>> list=baseMapper.queryTransactionList(user.getUserId(),sn,user.getCreateDate());
        return list;
    }

    @Override
    public void addIsbenefited(Long transactionId) {
            baseMapper.addIsbenefited(transactionId);
    }

    @Override
    public Integer queryYhbBenefited(Long transactionId) {
        return baseMapper.queryYhbBenefited(transactionId);
    }

    @Override
    public List<CusTranView> queryCusTranList(String token, Integer pageNo) {
        YhbUser user = yhbUserService.queryUserByToken(token);
        Integer start=(pageNo-1)*10;
        List<Map<String, Object>> lists = baseMapper.queryCusTranList(user.getUserId(),start);
        //return getLastMonthsListByDate(lists);
        return PackUtils.packToCusTranView(lists,"transactionDate");
    }

    @Override
    public PageUtils queryTransactionPage(Map<String, Object> params) {
        Integer currpage = Integer.valueOf(params.get("page").toString());
        Integer pageSize = Integer.valueOf(params.get("limit").toString());
        params.put("start", (currpage - 1) * pageSize);
        params.put("limit", pageSize);
        List<Map<String,Object>> list=baseMapper.queryTranList(params);
        Integer count=baseMapper.queryTranCount(params);
        return new PageUtils(list, count, pageSize, currpage);




    }

    @Override
    public List<Map<String, Object>> queryTranAndCountList(String sn) {
        return baseMapper.queryTranAndCountList(sn);
    }

}
